<template>
  <div class="flex-y-center breadcrumb-wrapper" v-if="levelList.length && isShow">
    <img src="@/assets/img/icon-breadcrumb.png" class="icon-breadcrumb" />
    <span class="el-breadcrumb__inner">您当前位置：</span>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <transition-group name="breadcrumb">
        <el-breadcrumb-item v-for="(item, index) in levelList" :key="index" >
          <span  style="cursor:pointer" @click="navTo(item, index)">{{ item.meta.title }}</span>
        </el-breadcrumb-item>
      </transition-group>
    </el-breadcrumb>
  </div>
</template>

<script>
export default {
  name: "Breadcrumb",
  data() {
    return {
      isShow: true
    };
  },
  computed:{
    levelList(){
      const breadCrumbList = this.$store.getters.breadCrumbList
      if((this.$route.name === 'Index')){
        return []
      }
      return breadCrumbList;
    }
  },
  created() {
    this.$bus.$on('showBreadCrumb', isShow => {
      this.isShow = isShow
    })
  },
  methods: {
    navTo(item, index){
      let current = this.levelList.length - 1
      if(index === current) return
      history.go(-(current - index));
    }
  },
};
</script>

<style lang="scss" scoped>
.breadcrumb-wrapper {
  width: 1200px;
  justify-content: flex-start;
  padding: 25px 0;
  margin: auto;
}

.icon-breadcrumb {
  width: 18px;
  height: 18px;
  margin-right: 8px;
}

::v-deep .el-breadcrumb__item,
::v-deep .el-breadcrumb__item:last-child {
  display: flex;
  align-items: center;
  font-size: 16px;
}

::v-deep .el-breadcrumb__inner {
  font-weight: 400;
  font-size: 0.2rem;
  color: #000000;
  vertical-align: top;
  font-size: 16px;
}
</style>
